package com.course.designpatterns.singleton;

/**
 * @author ：Jack Hao
 * @date ：Created in 2021/6/20 20:53
 * @description：饿汉式
 * 类加载时加载，就实例化一个，JVM保证线程安全
 * 简单实用，推荐使用。
 *
 */
public class Mgr01
{
    private static final Mgr01 INSTANCE = new Mgr01();

    private Mgr01(){};

    public static Mgr01 getInstance(){
        return INSTANCE;
    }

    public static void main(String[] args)
    {
        //获取两次实例
        Mgr01 m1 =  Mgr01.getInstance();
        Mgr01 m2 =  Mgr01.getInstance();
        System.out.println(m1 == m2);

        //这个类本身中还是可以 new 两个的
//        Mgr01 m3 =  new Mgr01();
//        Mgr01 m4 =  new Mgr01();
//        System.out.println(m3 == m4);
    }


}
